package org.cloudie.docs.editor.client.widgets;

import org.cloudie.docs.editor.client.behaviors.HasProxyBehavior;

import com.allen_sauer.gwt.dnd.client.PickupDragController;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ClonePanel extends HorizontalPanel {
	
  protected PickupDragController controller;
	
  public ClonePanel(PickupDragController controller, HasProxyBehavior w) {
	this.controller = controller;
	if (w instanceof Widget) {
      Widget widget = (Widget) w;
	  controller.makeDraggable(widget);
      super.add(widget);
	}
  }
	
  @Override
  public void add(Widget w) {
    return;
  }
	
  @Override
  public void insert(Widget w, int beforeIndex) {
    return;
  }
  
  @Override
  public boolean remove(Widget w) {
    HasProxyBehavior ei = (HasProxyBehavior) w;
	if (!ei.isProxy()) {
	  ExplorerIcon proxy = (ExplorerIcon) ei.getProxy();
	  proxy.setProxy(false);
	  ei.setProxy(true);
	  controller.makeDraggable(proxy);
	  super.add(proxy);
	}
    return super.remove(w);
  }

}